//
//  AddressBookV2.m
//  OC05_数组_字典_集合
//
//  Created by dllo on 16/3/2.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "AddressBookV2.h"

@implementation AddressBookV2

#pragma mark - init
/** 属性字典初始化并添加26个键值对. */
- (instancetype)init {
    self =[super init];
    if (self) {
        _contactDic = [NSMutableDictionary dictionary];

        for (char c = 'A'; c <= 'Z'; c++) {
            // 创建数组.
            NSMutableArray *contactArray = [NSMutableArray array];
            // 创建key.
            NSString *key = [NSString stringWithFormat:@"%c", c];
            // 核心API. 添加键值对.
            [_contactDic setObject:contactArray forKey:key];
        }
    }
    
    return self;
    
}
#pragma mark - function
/**
 * 根据联系人的分组名, 在_contactDic字典中找出对应的输入, 然后将联系人添加到此数组中.
 */
- (void)addContact:(Contact *)contact {
    
    NSString *groupName = contact.groupName;
    
    NSMutableArray *array = [self.contactDic objectForKey:groupName];
    
    [array addObject:contact];
}

- (void)viewAllContact {
    NSLog(@"%@",self.contactDic);
}

- (void)removeAllcontact {
    //遍历字典,获取每一个数组
    for (NSString *key in self.contactDic) {
            
        [[self.contactDic objectForKey:key] removeAllObjects];//删除数组当中的所有联系人对象.
            
    }
    NSLog(@"移除成功");
}


@end
